import Vue from 'vue'
import VueRouter from 'vue-router'
// 路由懒加载
const Login = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Login.vue')
const Home = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Home.vue')
const Welcome = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/Welcome.vue')
const Users = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/user/User.vue')
const Roles = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/power/Roles.vue')
const Rights = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/power/Rights.vue')
const Order = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/order/Order.vue')
const List = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/goods/List.vue')
const Cate = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/goods/Cate.vue')
const Params = () => import(/* webpackChunkName: "Login_Home_Welcome" */ '../components/goods/Params.vue')
Vue.use(VueRouter)
const routes = [
  { path: '*', redirect: '/home' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/Welcome',
    children: [
      { path: '/home', component: Welcome },
      { path: '/users', component: Users },
      { path: '/roles', component: Roles },
      { path: '/rights', component: Rights },
      { path: '/order', component: Order },
      { path: '/list', component: List },
      { path: '/categories', component: Cate },
      { path: '/params', component: Params },
    ]
  }
]
const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const token = window.sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})
export default router
